package com.powernode.controller;

import com.powernode.common.Result;
import com.powernode.domain.StatBean;
import com.powernode.dto.StatDto;
import com.powernode.service.StatService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 内容: 统计图表的接口
 * 作者: 动力节点 武汉
 */
@RestController
@RequestMapping("stat")
public class StatController {

    @Resource
    private StatService statService;

    /**
     * 拜访量统计
     */
    @GetMapping("statVisitLogCount.do")
    public Result statVisitLogCount(StatDto statDto){
        try {
            List<StatBean> statBeanList=this.statService.queryVisitLogCount(statDto);
            List<String> names=new ArrayList<>();
            List<Integer> values=new ArrayList<>();
            for (StatBean statBean : statBeanList) {
                names.add(statBean.getName());
                values.add(statBean.getValue());
            }
            //把names和values放到map
            Map<String,Object> res=new HashMap<>();
            res.put("name",names);
            res.put("value",values);
            return new Result(200,"查询成功",0L,res);
        }catch (Exception e){
            e.printStackTrace();
            return new Result(-1,"查询失败");
        }


    }
}
